package dingding

import (
	dingtalkworkflow_1_0 "github.com/alibabacloud-go/dingtalk/workflow_1_0"
	"github.com/alibabacloud-go/tea/tea"
	"wonlicsys/constPack"
)

// TexFieldComponents @Description 表单必传参数
type TexFieldComponents struct {
	ComponentId          string //控件唯一id
	LiableName           string //控件标题
	Placeholder          string //输入提示
	StatFieldComponentId string //设置对数字、金额类控件
	FormCode             string // 关联表单的formCode
	ProcessCode          string //ProcessCode
}

//GetTextFieldComponents  @Description: 单行输入控件
//@param textCom
// @return error
func GetTextFieldComponents(textCom *TexFieldComponents) *dingtalkworkflow_1_0.FormComponent {
	//设置对数字、金额类控件进行总数统计
	formComponents0PropsStatField0 := &dingtalkworkflow_1_0.FormComponentPropsStatField{
		ComponentId: tea.String(textCom.StatFieldComponentId),
		Label:       tea.String("金额(元)"),
	}

	//关联数据源配置
	formComponents0PropsDataSourceTarget := &dingtalkworkflow_1_0.FormDataSourceTarget{
		AppUuid:  tea.String(constPack.DingAppKey),
		AppType:  tea.Int32(0),
		FormCode: tea.String(textCom.FormCode),
	}
	formComponents0PropsDataSource := &dingtalkworkflow_1_0.FormDataSource{
		Type:   tea.String("form"),
		Target: formComponents0PropsDataSourceTarget,
	}

	formComponents0PropsAvailableTemplates0 := &dingtalkworkflow_1_0.AvaliableTemplate{
		Name:        tea.String("出差申请"),
		ProcessCode: tea.String(textCom.ProcessCode),
	}

	//oapi表单组件属性模型
	formComponentsTextProps := &dingtalkworkflow_1_0.FormComponentProps{
		ComponentId:        tea.String(textCom.ComponentId), //表单控件的唯一Id
		Label:              tea.String(textCom.LiableName),  //控件标题
		Placeholder:        tea.String(textCom.Placeholder),
		StatField:          []*dingtalkworkflow_1_0.FormComponentPropsStatField{formComponents0PropsStatField0},
		DataSource:         formComponents0PropsDataSource,
		AvailableTemplates: []*dingtalkworkflow_1_0.AvaliableTemplate{formComponents0PropsAvailableTemplates0}, //关联审批单控件限定模板列表
		TableViewMode:      tea.String("table"),
		Disabled:           tea.Bool(false),
	}

	//表单控件列表TextField
	formComponentsText := &dingtalkworkflow_1_0.FormComponent{
		ComponentType: tea.String("TextField"),
		Props:         formComponentsTextProps,
		Children:      []*dingtalkworkflow_1_0.FormComponent{}, //子组件
	}

	//具体text 表单参数

	return formComponentsText
}

// TexFieldComponents @Description 表单必传参数
type PhotoFieldComponents struct {
	ComponentId string //控件唯一id
	LiableName  string //控件标题
}

func GetPhotoField(photoComp *PhotoFieldComponents) *dingtalkworkflow_1_0.FormComponent {
	formComponentsPhotoProps := &dingtalkworkflow_1_0.FormComponentProps{
		ComponentId: tea.String(photoComp.ComponentId), //表单控件的唯一Id
		Label:       tea.String(photoComp.LiableName),  //控件标题
		Required:    tea.Bool(false),
	}

	//表单控件列表TextField
	formComponentsPhoto := &dingtalkworkflow_1_0.FormComponent{
		ComponentType: tea.String("DDPhotoField"),
		Props:         formComponentsPhotoProps,
		Children:      []*dingtalkworkflow_1_0.FormComponent{}, //子组件
	}

	return formComponentsPhoto
}
